/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.relatorios;

import br.com.deployment.entidade.protocolo.Protocolo;
import br.com.deployment.entidade.protocolo.ServicoProtocolo;
import br.com.deployment.entidade.selo.Selo;
import br.com.deployment.servico.ProtocoloServico;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author elyjr
 */
@ManagedBean
@ViewScoped
public class ManagerRelatorioSeloProtocolo implements Serializable{

    @EJB
    ProtocoloServico protocoloServico;
    
    private List<ServicoProtocolo> servicoProtocolo;
    private Protocolo protocolo;
    private Date data;
    private Date dataFinal;

    
    @PostConstruct
    public void init(){
        servicoProtocolo = new ArrayList<ServicoProtocolo>();
    }

    public Date getDataFinal() {
        return dataFinal;
    }

    public void setDataFinal(Date dataFinal) {
        this.dataFinal = dataFinal;
    }
    
    
    public Date getData() {
        return data;
    }

    public List<ServicoProtocolo> getServicoProtocolo() {
        return servicoProtocolo;
    }

    public void setServicoProtocolo(List<ServicoProtocolo> servicoProtocolo) {
        this.servicoProtocolo = servicoProtocolo;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public Protocolo getProtocolo() {
        return protocolo;
    }

    public void setProtocolo(Protocolo protocolo) {
        this.protocolo = protocolo;
    }
    
    
    public void clean(){
        data = null;
        init();
    }
    
    /**
     * Pesquisar por Data e retorna uma lista de ServiçoProtocolo
     */
    public void pesquisar() {
        servicoProtocolo = protocoloServico.relatorioSeloProtocolo(data, dataFinal);
    }
    
    /**
     * Gera o relatório baseado no resul do método pesquisar.
     */
    public void gerarRelatorio(){
        protocoloServico.relatorioSeloProtocolo(servicoProtocolo);
    }
    
    public BigDecimal valorDoProtocolo(Protocolo protocolo){
        BigDecimal total = new BigDecimal(0);
        for( ServicoProtocolo sp :  protocolo.getServicoProtocolos()){
            total = total.add( sp.getValor());
        }
        return total;
    }

 
}
